package com.njust.controller;

import com.njust.Util.AliOssUtil;
import com.njust.domain.dto.VideoDTO;
import com.njust.domain.dto.VideoPageQueryDTO;
import com.njust.domain.vo.PageQueryVO;
import com.njust.domain.vo.PageQueryVO;
import com.njust.result.Result;
import com.njust.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

/**
 * @version 1.0
 * @Author Imak
 * @Date 2024/11/10 16:42
 * @视频接口
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/video")
@Slf4j
public class VideoController {


    @Autowired
    private VideoService videoService;

    /**
     * 上传视频
     * @param videoDTO
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestBody VideoDTO videoDTO){
        log.info("视频上传：{}",videoDTO);
        videoService.uploadVideo(videoDTO);
        return Result.success("视频上传成功！");
    }

    /**
     * 视频分页查询
     * @param videoPageQueryDTO
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageQueryVO> pageQuery(VideoPageQueryDTO videoPageQueryDTO){
        log.info("视频分页查询，参数为：{}",videoPageQueryDTO);
        PageQueryVO PageQueryVO=videoService.pageQuery(videoPageQueryDTO);
        return Result.success(PageQueryVO);
    }

    /**
     * 视频播放
     * @param video_id
     * @return
     */
    @GetMapping("watch/{video_id}")
    public Result<String> watchVideo(@PathVariable int video_id){
        String video_link=videoService.watchVideo(video_id);
        if (video_link!=null) {
            log.info("视频播放成功，{}",video_id);
            return Result.success(video_link,"视频播放成功!");
        } else {
            return Result.error("未找到对应视频ID的视频");
        }

    }
}
